using System;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Testing.Core
{
	public delegate ReturnType TimedOperation<ReturnType>();

	public class TestBase
	{
		protected ReturnType TimeOperation<ReturnType>( string description, TimedOperation<ReturnType> operation )
		{
			DateTime mark = DateTime.Now;
			ReturnType result = operation();
			WriteTime( description, mark );
			return result;
		}

		protected void TimeOperation( string description, ThreadStart operation )
		{
			DateTime mark = DateTime.Now;
			operation();
			WriteTime( description, mark );
		}

		void WriteTime( string description, DateTime time )
		{
			TestContext.WriteLine( "Timer {0}: [{1}ms]", description, ( DateTime.Now - time ).TotalMilliseconds );
		}

		///<summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get { return testContextInstance; }
			set { testContextInstance = value; }
		}	TestContext testContextInstance;
	}
}